<?php
/***********************************************************
	Filename: app/www/control/register.php
	Note	: 用户控制面板
	Version : 3.0
	Author  : qinggan
	Update  : 2010-05-04
***********************************************************/
class register_c extends Control
{
	function __construct()
	{
		parent::Control();
		$this->load_model("user");
	}

	function register_c()
	{
		$this->__construct();
	}

	function index_f()
	{
		if($_SESSION["user_id"])
		{
			error("您已经是会员了，不需要重新注册",$this->url());
		}

		$sitetitle = "会员注册";
		$this->tpl->assign("sitetitle",$sitetitle);
		$array[0]["title"] = "会员注册";
		$this->tpl->assign("leader",$array);
		$this->tpl->display("register.".$this->tpl->ext);
	}

	//存储个人信息
	function setok_f()
	{
		if($_SESSION["user_id"])
		{
			error("您已经是会员了，不需要重新注册",$this->url());
		}
		$array = array();
		$array["email"] = $this->trans_lib->safe("email");
		$array["name"] = $this->trans_lib->safe("name");
		$newpass = $this->trans_lib->safe("newpass");
		$chkpass = $this->trans_lib->safe("chkpass");
		if(!$newpass || !$chkpass)
		{
			error("密码不允许为空！",$this->url("register"));
		}
		if($newpass != $chkpass)
		{
			error("两次输入的密码不一致！",$this->url("register"));
		}
		$array["pass"] = sys_md5($newpass);
		if(!$array["email"])
		{
			error("会员邮箱不允许为空！",$this->url("register"));
		}
		$chkname = $this->chkname($array["name"]);
		if($chkname != "ok")
		{
			error($chkname,$this->url("register"));
		}
		$user_id = $this->user_m->save($array);
		//会员注册成功，模拟登录
		$_SESSION["user_id"] = $user_id;
		$_SESSION["user_name"] = $array["name"];
		//发送欢迎信息
		$this->load_lib("email");
		$this->email_lib->reg($user_id);
		error("您的账号注册成功！",$this->url("usercp"));
	}

	//检测会员是否存在
	function chkname_f()
	{
		$name = $this->trans_lib->safe("name");
		exit($this->chkname($name));
	}

	function chkname($name)
	{
		if(!$name)
		{
			return "账号不允许为空！";
		}
		$rs = $this->user_m->user_from_name($name);
		if($rs)
		{
			return "账号已经存在！";
		}
		else
		{
			return "ok";
		}
	}
}
?>